Skip to content

fix: improve tcsh completion support#9503

Draft
ThomasWaldmann wants to merge 1 commit intoborgbackup:masterfrom
ThomasWaldmann:tcsh-completions
Draft

fix: improve tcsh completion support#9503
ThomasWaldmann wants to merge 1 commit intoborgbackup:masterfrom
ThomasWaldmann:tcsh-completions

Conversation

@ThomasWaldmann
Copy link
Member

@ThomasWaldmann ThomasWaldmann commented Mar 18, 2026

This commit fixes critical evaluation crashes in the generated tcsh completion script and significantly cleans up the Python generation logic:

  • monkeypatch shtab to natively support positional completion under subcommands for tcsh (e.g., borg help <topic>).
  • fix "if: Empty if." errors in tcsh by injecting array bounds checks ($#cmd >= max_idx) inside the monkeypatched shtab generator.
  • fix recursive parser crashes in tcsh by replacing unescaped nested backticks (...) with safe eval evaluations.
  • deduplicate tcsh fallback rules to reduce the script payload size, preventing tcsh memory buffer truncations that led to cryptic "Illegal variable name." exceptions.
  • no support yet for archive, aid:, and tags completion features for tcsh

Description

Checklist

  • PR is against master (or maintenance branch if only applicable there)
  • New code has tests and docs where appropriate
  • Tests pass (run tox or the relevant test subset)
  • Commit messages are clean and reference related issues

This commit fixes critical evaluation crashes in the generated tcsh completion script and significantly cleans up the Python generation logic:

- monkeypatch shtab to natively support positional completion under subcommands for tcsh (e.g., `borg help <topic>`).
- fix "if: Empty if." errors in tcsh by injecting array bounds checks (`$#cmd >= max_idx`) inside the monkeypatched shtab generator.
- fix recursive parser crashes in tcsh by replacing unescaped nested backticks (`...`) with safe `eval` evaluations.
- deduplicate tcsh fallback rules to reduce the script payload size, preventing tcsh memory buffer truncations that led to cryptic "Illegal variable name." exceptions.
- no support yet for archive, aid:, and tags completion features for tcsh
@ThomasWaldmann
Copy link
Member Author

This was created with AI assistance (Gemini Flash/Pro) and likely needs more work:

  • that monkeypatching of shtab isn't pretty. IF there are bugs / missing features in shtab tcsh support, they should be fixed there.
  • archivename / aid completion is missing. The AI tried to write that, but ran into severe troubles. To at least have something simpler to begin with, I decided to skip that for the initial commit.

@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 90.24390% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.40%. Comparing base (1356aeb) to head (952d70a).
⚠️ Report is 13 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/borg/archiver/completion_cmd.py 90.24% 2 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9503      +/-   ##
==========================================
+ Coverage   83.36%   83.40%   +0.04%     
==========================================
  Files          87       87              
  Lines       15439    15523      +84     
  Branches     2309     2336      +27     
==========================================
+ Hits        12870    12947      +77     
- Misses       1818     1821       +3     
- Partials      751      755       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ThomasWaldmann
Copy link
Member Author

@simaoafonso-pwt Could you have a look at that monkeypatch please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant